/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.bus.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.bus.entity.EntHistory;
import com.thinkgem.jeesite.modules.bus.service.EntHistoryService;

/**
 * 企业备案历史表Controller
 * @author zhangxingliang
 * @version 2019-06-10
 */
@Controller
@RequestMapping(value = "${adminPath}/bus/entHistory")
public class EntHistoryController extends BaseController {

	@Autowired
	private EntHistoryService entHistoryService;
	
	@ModelAttribute
	public EntHistory get(@RequestParam(required=false) String id) {
		EntHistory entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = entHistoryService.get(id);
		}
		if (entity == null){
			entity = new EntHistory();
		}
		return entity;
	}
	
	@RequiresPermissions("bus:entHistory:view")
	@RequestMapping(value = {"list", ""})
	public String list(EntHistory entHistory, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<EntHistory> page = entHistoryService.findPage(new Page<EntHistory>(request, response), entHistory); 
		model.addAttribute("page", page);
		return "modules/bus/entHistoryList";
	}

	@RequiresPermissions("bus:entHistory:view")
	@RequestMapping(value = "form")
	public String form(EntHistory entHistory, Model model) {
		model.addAttribute("entHistory", entHistory);
		return "modules/bus/entHistoryForm";
	}

	@RequiresPermissions("bus:entHistory:edit")
	@RequestMapping(value = "save")
	public String save(EntHistory entHistory, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, entHistory)){
			return form(entHistory, model);
		}
		entHistoryService.save(entHistory);
		addMessage(redirectAttributes, "保存企业备案历史表成功");
		return "redirect:"+Global.getAdminPath()+"/bus/entHistory/?repage";
	}
	
	@RequiresPermissions("bus:entHistory:edit")
	@RequestMapping(value = "delete")
	public String delete(EntHistory entHistory, RedirectAttributes redirectAttributes) {
		entHistoryService.delete(entHistory);
		addMessage(redirectAttributes, "删除企业备案历史表成功");
		return "redirect:"+Global.getAdminPath()+"/bus/entHistory/?repage";
	}

}